605e896d6c3aa8da2eaa74853077e37f5623a36d,source/net/yacy/document/parser/pdfParser.java,pdfParser,parse,#DigestURI#String#String#InputStream#,86

Before Change


            // delete the file
            if (writerFile != null) FileUtils.deletedelete(writerFile);
            
            Log.logException(e);
            throw new ParserException("Unexpected error while parsing pdf file. " + e.getMessage(),location); 
        } finally {
            if (theDocument != null) try { theDocument.close(); } catch (final Exception e) {/* ignore this */}

After Change


            stripper = new PDFTextStripper();
            theDocument = parser.getPDDocument();
        } catch (IOException e) {
            Log.logException(e);
            throw new ParserException(e.getMessage(), location);
        } finally {
            Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
        }
        
        if (theDocument.isEncrypted()) {
            try {
                theDocument.openProtection(new StandardDecryptionMaterial(""));
            } catch (BadSecurityHandlerException e) {
                Log.logException(e);
                throw new ParserException("Document is encrypted (1): " + e.getMessage(), location);
            } catch (IOException e) {
                Log.logException(e);
                throw new ParserException("Document is encrypted (2): " + e.getMessage(), location);
            } catch (CryptographyException e) {
                Log.logException(e);
                throw new ParserException("Document is encrypted (3): " + e.getMessage(), location);
            }
            final AccessPermission perm = theDocument.getCurrentAccessPermission();
            if (perm == null || !perm.canExtractContent())
                throw new ParserException("Document is encrypted and cannot decrypted", location);
        }
        
        // extracting some metadata
        final PDDocumentInformation theDocInfo = theDocument.getDocumentInformation();            
        if (theDocInfo != null) {
            docTitle = theDocInfo.getTitle();
            docSubject = theDocInfo.getSubject();
            docAuthor = theDocInfo.getAuthor();
            docKeywordStr = theDocInfo.getKeywords();
        }            
        
        try {
            // creating a writer for output
            if ((this.contentLength == -1) || (this.contentLength > Idiom.MAX_KEEP_IN_MEMORY_SIZE)) {
                writerFile = File.createTempFile("pdfParser",".prt");
                writer = new OutputStreamWriter(new FileOutputStream(writerFile),"UTF-8");
            } else {
                writer = new CharBuffer(); 
            }
            try {
                stripper.writeText(theDocument, writer ); // may throw a NPE
            } catch (Exception e) {
                Log.logException(e);
                Log.logWarning("pdfParser", e.getMessage());
            }
            theDocument.close(); theDocument = null;            
            writer.close();
        } catch (IOException e) {
            Log.logException(e);
            // close the writer
            if (writer != null) try { writer.close(); } catch (final Exception ex) {}